package com.wze.wze.Controller;

import com.wze.wze.Aop.PasToken;
import com.wze.wze.Entity.PingLun;
import com.wze.wze.Entity.ResultEntity;
import com.wze.wze.Entity.v_pl;
import com.wze.wze.Service.PingLunService;
import com.wze.wze.Service.v_plService;
import com.wze.wze.Util.JSONTool;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin //解决跨域
@RestController //控制器注解
@RequestMapping("/vPingLun/")//请求路径
public class v_plController {
    @Resource
    v_plService v_plService;
    ResultEntity resultEntity = null;

    @PasToken
    @GetMapping("pinglunList")
    private String PlList(
            @RequestParam("page") int page,
            @RequestParam("limit") int limit,
            @RequestParam("MusicName")  String MusicName,
            @RequestParam("Uname")  String Uname
    ){
        try {
            resultEntity = new ResultEntity();
            int Start = (page-1) * limit;//计算分页位置
            List<v_pl> list = v_plService.getPingLunList(Start, limit, MusicName, Uname);
            if(Uname.equals("") || !MusicName.equals("")){//有条件
                resultEntity.setCount(String.valueOf(list.size()));
            }else {//没有查询条件
                resultEntity.setCount(String.valueOf(v_plService.getPlCount()));
            }
            resultEntity.setCode("0");
            resultEntity.setData(list);
            resultEntity.setMsg("查询成功!");
        }catch (Exception e){
            resultEntity.setCode("1");
            resultEntity.setMsg("查询失败!"+e.getMessage());
        }
        return JSONTool.getJsonTool().toJson(resultEntity);
    }



    @PasToken
    @GetMapping("pingluList")
    private String PlList(
            @RequestParam("page") int page,
            @RequestParam("limit") int limit,
            @RequestParam("Mid")  int Mid,
            @RequestParam("Uname")  String Uname
    ){
        try {
            resultEntity = new ResultEntity();
            int Start = (page-1) * limit;//计算分页位置
            List<v_pl> list = v_plService.getPingLuList(Start, limit, Mid, Uname);
            if(Uname.equals("") || Mid!=-1){//有条件
                resultEntity.setCount(String.valueOf(list.size()));
            }else {//没有查询条件
                resultEntity.setCount(String.valueOf(v_plService.getPlCount()));
            }
            resultEntity.setCode("0");
            resultEntity.setData(list);
            resultEntity.setMsg("查询成功!");
        }catch (Exception e){
            resultEntity.setCode("1");
            resultEntity.setMsg("查询失败!"+e.getMessage());
        }
        return JSONTool.getJsonTool().toJson(resultEntity);
    }
    
}
